package hbnu.stockManage.repository;

import hbnu.stockManage.util.Db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


//创建管理员数据访问类
public class AdminRepository {
    public boolean exists(String username, String password) {
         String sql = "SELECT * FROM admin WHERE username = ? AND password = ? limit 1";
        try (Connection c = Db.getConnection();
             PreparedStatement ps = c.prepareStatement(sql)) {
            ps.setString(1, username);
            ps.setString(2, password);
            try (ResultSet rs = ps.executeQuery()) {
                return rs.next();
            }
        } catch (SQLException e) {
            System.out.println("登录校验失败: " + e.getMessage());
            return false;
        }
    }
}
